﻿@model OT.Areas.Admin.Models.Categories
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
    <h3 id="myModalLabel">Create Category</h3>
</div>
<div class="modal-body">
    <div id="alert_modal">
        @Html.ValidationSummary()
    </div>
    <div class="form-horizontal" role="form">
        <div class="form-group">
            <div class="col-lg-13">
                <div id="divMsgCre"></div>
            </div>
        </div>
        <div class="form-group" id="divCategoryName">
            <label class="col-lg-3 control-label">Category Name</label>
            <div class="col-lg-5">
                <input class="form-control" type="text" placeholder="Enter Category Name" id="CategoryName">
            </div>
        </div>
        <div class="form-group" id="divDescription">
            <label class="col-lg-3 control-label">Description</label>
            <div class="col-lg-5">
                <textarea class="form-control" placeholder="Enter Description" id="Description" rows="3"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-3 control-label">Select SubCategory</label>
            <div class="col-lg-5">
                @Html.DropDownListFor(model => model.SubCategoryID, new SelectList(Model.SubCategories, "CategoryID", "CategoryName"), "--Select--", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.SubCategoryID)
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-3 control-label">Status</label>
            <div class="col-lg-1">
                <input class="form-control" id="st" name="st" type="checkbox">
            </div>
        </div>
    </div>
</div>
<div class="modal-footer">
    <button class="btn btn-default" type="submit" id="btnCreate"><i class="icon-cog"></i>Save</button>
    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><i class="icon-off"></i>Cancel</button>
</div>
<script type="text/javascript">
    $("#btnCreate").click(function (e) {
        var CategoryID = $("#HDFID").val();
        var CategoryName = $("#CategoryName").val();
        var Description = $("#Description").val();
        if ($("#st").is(':checked')) {
            Status = true;
        }
        else {
            Status = false;
        }
        var SubCategory = $("#SubCategoryID").val();
        e.preventDefault();
        if (CategoryName == '') {
            showMsg("divMsgCre", "Enter All Required Value", "danger");
            (CategoryName == '') ? $('#divCategoryName').addClass('has-error') : $('#divCategoryName').removeClass('has-error');
        }
        else {
            $.ajax({
                url: "/Admin/Category/Create?CategoryName=" + CategoryName + "&Description=" + Description + "&status=" + Status + "&subcategory=" + SubCategory,
                type: "POST",
                success: function (result) {
                    if (result != "NotValid") {
                        $('#modalDiv').modal('hide');
                        showMsg('divMsgIndex', 'Record Saved Successfuly', 'success');
                        loadPage(1, 10, '');
                    }
                    else {
                        showMsg('divMsgCre', 'Data Not Saved! ERROR', 'danger');
                    }
                },
                error: function (data) {
                }
            });
        }
        return false;
    });
</script>

